
package smashedapples.mvc
{

	import flash.events.Event;

	import mx.core.Application;
	import mx.events.FlexEvent;


	public class FlexApp extends Application
	{

		public function FlexApp()
		{
			//this.addEventListener( Cmd.TYPE, handleCommandDispatch, true, 1 );
			//this.addEventListener( Event.ENTER_FRAME, handleEnterFrame );

			this.addEventListener( FlexEvent.PREINITIALIZE, handlePreInitialize );
			this.addEventListener( FlexEvent.CREATION_COMPLETE, handleCreationComplete );
			this.addEventListener( Event.ENTER_FRAME, handleEnterFrame );
		}

		protected function handleAppEvent( event:AppEvent ):void
		{

			trace( "FlexApp::handleAppEvent=" + event.target );
		}





		protected function handlePreInitialize( event:FlexEvent ):void
		{
			//trace( "FlexApp::handlePreInitialize=" + event.target );
			this.systemManager.addEventListener( FlexEvent.CREATION_COMPLETE, handleObjectCreationComplete, true );


		}

		protected function handleObjectCreationComplete( event:FlexEvent ):void
		{
			//trace( "FlexApp  ::handleObjectCreationComplete=" + event.target );
		}

		protected function handleCreationComplete( event:FlexEvent ):void
		{
			//trace( "FlexApp::handleCreationComplete=" + event.target[ "id" ]);
		}


		private function handleEnterFrame( event:Event ):void
		{
		}

		override public function dispatchEvent( event:Event ):Boolean
		{
			//trace( "FlexApp::dispatchEvent=" + event.type );
			return super.dispatchEvent( event );
		}


		override protected function updateDisplayList( unscaledWidth:Number, unscaledHeight:Number ):void
		{
			super.updateDisplayList( unscaledWidth, unscaledHeight );
			//trace( "FlexApp::updateDisplayList" );
		}

		override protected function commitProperties():void
		{
			super.commitProperties();

			for each( var event:String in this.appEvents )
			{
				this.addEventListener( event, handleAppEvent, true );
			}
		}

		public var appEvents:Array = [];


	}
}